package Euler21;

import java.util.*;

import ReusableCode.*;

public class AmicableNumbers {
	public static void main(String[] args) {
		int upperbound = 10000;
		long sum = 0;
		
		//Generate d values.
		List<Long> dvals = new ArrayList<Long>();
		for (int i = 0; i <= upperbound; i++)
		{
			dvals.add(MathFunctions.getSetSum(MathFunctions.getProperDivisors(i)));
		}
		
		int size = dvals.size();
		for (int i = 1; i < size; i++)
		{
			int val = MathFunctions.safeLongToInt(dvals.get(i));
			
			if(val < size){
				if((i == dvals.get(val)) && val != i)
				{
					System.out.println(i + " " + val);
					sum += i;
				}
			}
			//System.out.println(i + " " + dvals.get(i));
		}
		
		System.out.println(sum);
	}
}
